#include "admin.h"
#include "ui_admin.h"
#include "admin_student.h"
#include "sheguan.h"
#include <QPushButton>
#include <QtDebug>

Admin::Admin(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::Admin)
    , m_studentPage(nullptr)
    , m_sheguanPage(nullptr)
{
    ui->setupUi(this);
    initPage();
}

Admin::~Admin()
{
    delete ui;
}

void Admin::initPage()
{
    m_studentPage = new admin_student(this);
    m_sheguanPage = new sheguan(this);
    ui->stackedWidget->addWidget(m_studentPage);
    ui->stackedWidget->addWidget(m_sheguanPage);
    ui->stackedWidget->setCurrentIndex(0);

    auto l = ui->widget->children();
    for (auto it : l)
    {
        if (it->objectName().contains("pushButton"))
        {
            connect(static_cast<QPushButton*>(it), &QPushButton::clicked, this, &Admin::dealMenu);
        }
    }
}


void Admin::dealMenu()
{
    auto str = sender()->objectName();
    do
    {
        if ("pushButton_student" == str)
        {
            ui->stackedWidget->setCurrentIndex(0);
            break;
        }
        if ("pushButton_sheguan" == str)
        {
            ui->stackedWidget->setCurrentIndex(1);
            break;
        }

    } while (false);
}




void Admin::on_pushButton_exit_clicked()
{
    this->close();
}

